/*
 * Created on Mar 1, 2005
 */
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

import javax.swing.Timer;
/**
 * @author Jesse Phillips
 */
public class TimeTracker implements ActionListener {
    private Frame myFrame;
    private String affect;
    private Graphics g;
    private int delta = 0, time;
    private Timer timeIt, bRate;
    private TimeTracker blip;
    private Objects myObj, player;
    private DrawMe objDraw;
    private boolean fallTime, rndFall = false;
    
    public TimeTracker(Objects o, boolean f) {
        myObj = o;
        fallTime = f;
    }
    
    public TimeTracker(DrawMe oD) {
    	affect = "flash";
    	objDraw = oD;
    }
    
    public TimeTracker(DrawMe oD, Objects p) {
    	rndFall = true;
    	objDraw = oD;
    	player = p;
    }
    public TimeTracker(Objects o) {
    	fallTime = false;
    	myObj = o;
    }

    public void actionPerformed(ActionEvent e) {
		 // What do you do when an action happens?
		 /*ans bl*/
    	if(affect == "flash") {
    		objDraw.rect(0, 0, 600, 400, Color.white, true);
    		timeIt.stop();
    	}else {
	    	if(!rndFall){
		    	if(!fallTime) {
		    		myObj.drawObj();
		    	} else {
		    		myObj.velocityIncr();
		    	}
	    	}else {
	    		if(objDraw.getBallNum() < 20) {
		    		myObj = new Objects(rndNum(400), 60, 50, 50, "circle", true, objDraw, player, bRate);
		    		myObj.start(0, 0);
		    		objDraw.string("Game Over", Color.white);
		    		objDraw.string("Click to START", Color.white);
	    		}else {
	    			gameOver();
	    		}
	    	}
    	}
		/*ans ab*/
    	
    }
    
    public String giveA() {
        return affect;
    }
    
    public void setTimeIt(Timer t) {
        timeIt = t;
    }
    
    public void gameOver() {
		objDraw.rect(0, 0, 400, 400, Color.white, true);
		objDraw.string("Game Over", Color.black);
		bRate.stop();
		objDraw.gameOver();
	}
    
    public int rndNum(int max) {
		int value = 0;
		Random myRandom = new Random();
		value = myRandom.nextInt(max);
		
		return value;
	}

	public void addTimer(Timer ballRate) {
		bRate = ballRate;
	}
    
}
